<template lang="html">
  <div class="scheduling-push-history">
    <nav-header>
      <template slot="menuBefore">
        <li>
          <router-link to="/affairs/teacherTop/top-list">名师列表</router-link>
        </li>
        <li class="gap">&gt;</li>
      </template>
    </nav-header>
    <div class="zh-table">
      <div class="zh-table-open clear">
        <div class="zh-open-left fl">
          <!-- <div class="open-width">
              <el-date-picker
                  type="daterange"
                  :editable="false"
                  :clearable="false"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                  v-model="pickerDate"
                  style="width: 100%;">
              </el-date-picker></div> -->
          <div class="open-width">
            <el-input placeholder="教师名称" v-model="keyword" @keyup.enter.native="search"></el-input>
          </div>
          <el-button type="primary" @click="search">搜索</el-button>
          <el-button type="primary" @click="reset">重置</el-button>
        </div>
        <div class="zh-open-right fr">
          <el-button type="danger" @click="delAll">批量删除</el-button>
        </div>
      </div>
      <div class="zh-table-contents" v-loading="dataLoading.status" :element-loading-text="dataLoading.txt">
        <el-table
          :data="listData"
          border
          @selection-change="tableSelectionChange"
          max-height="600"
          style="width: 100%">
          <el-table-column
            fixed
            type="selection"
            width="50"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="user_name"
            label="教师名称"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="number"
            label="账号"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="subject_name"
            label="任教科目"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop=""
            label="任教班级"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              {{$store.state.platformInformation ? scope.row.school_name + '-' : ''}}{{scope.row.org_names}}
            </template>
          </el-table-column>
          <el-table-column
            prop="platform_names"
            label="推荐至"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="statusTxt"
            label="状态"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            fixed="right"
            prop="handle"
            label="操作"
            align="center"
            width="250"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <!--多级-->
              <div v-if="scope.row.info_pt">
                <el-button v-if="scope.row.status === 3" type="text" @click="againPost(scope.row)">重新提交
                </el-button>
                <el-button v-else-if="scope.row.status === 2" type="text" class="delete-button"
                           @click="removeTergger(scope.row)">撤销
                </el-button>
                <el-button v-else type="text" class="delete-button" @click="delTergger(scope.row,'one')">删除记录</el-button>
              </div>
              <!--单机-->
              <div v-else>
                <el-button v-if="scope.row.status === 3" type="text" @click="checkReject(scope.row)">拒绝理由</el-button>
                <el-button type="text" class="delete-button" @click="delTergger(scope.row,'one')">删除记录</el-button>
                <el-button v-if="scope.row.status === 2" type="text" class="delete-button" @click="removeTergger(scope.row)">撤销</el-button>
              </div>

            </template>
          </el-table-column>
        </el-table>
        <div class="table-pagination" v-show="total_number > 10">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="listParam.page_index"
            :page-sizes="[10, 20, 30, 40, 50, 100]"
            :page-size="listParam.page_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total_number">
          </el-pagination>
        </div>
      </div>
    </div>
    <!-- 推上级无需理由，撤销也无需理由 -->
    <el-dialog
      title="拒绝理由"
      :visible.sync="rejectFlag"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      width="30%"
    >
      <div class="textarea-box" v-text="rejectTxt ? rejectTxt : '暂无拒绝理由'"></div>
      <span slot="footer" class="dialog-footer">
            <el-button @click="rejectFlag = false">取 消</el-button>
            <el-button type="primary" @click="rejectFlag = false">确 定</el-button>
        </span>
    </el-dialog>
    <el-dialog
      title="删除"
      :visible.sync="delFlag"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      width="30%"
    >
      <div class="textarea-box">该直播进行中，删除该直播会导致直播结束，确认删除？</div>
      <span slot="footer" class="dialog-footer">
            <el-button @click="delFlag = false">取 消</el-button>
            <el-button type="primary" @click="delFlag = false">确 定</el-button>
        </span>
    </el-dialog>
    <el-dialog
      title="批量删除"
      :visible.sync="delAllFlag"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      width="30%"
    >
      <div class="textarea-box">该直播进行中，删除该直播会导致直播结束，确认删除？</div>
      <span slot="footer" class="dialog-footer">
            <el-button @click="delAllFlag = false">取 消</el-button>
            <el-button type="primary" @click="delAllFlag = false">确 定</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
import {mapGetters} from "vuex";

export default {
  computed: {
    ...mapGetters({
      isPlatformInof: 'get_platformInformation',//获取当前是教育局还是学校
      isPlatform: 'checkLevel',//获取当前是单机还是多级
      userInfo: 'userInfo', //用户信息
    }),
  },
  data() {
    return {
      rowLen: 0,
      dataLoading: {
        status: false,
        txt: '获取数据...'
      },
      delFlag: false,
      delAllFlag: false,
      rejectFlag: false,
      rejectTxt: '',/*拒绝理由 */
      listData: [],
      listParam: {
        keyword: '',
        date_begin: '',
        date_end: '',
        page_index: 1,
        page_size: 10,
      },
      keyword: '',
      pickerDate: [],
      total_number: 0,
      status: ['删除', '通过', '未审核', '拒绝', '移除', '撤销'],/*记录状态 */
      ids: [],
      user_multistage: JSON.parse(sessionStorage.getItem('user_multistage')), // 判断当前是否为多级版本
    }
  },
  mounted() {
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.dataLoading.status = true;
      let params = this.listParam;
      const success = res => {
        this.dataLoading.status = false;
        this.listData = res.data.data;
        console.log( this.listData)
        this.total_number = res.data.data_sum;
        this.listData.forEach(item => {
          this.$set(item, 'info_pt', this.isPlatform)
          this.$set(item, 'info_ptxx', this.isPlatformInof)
          item.statusTxt = this.status[parseInt(item.status)];
        })
      }
      this.$ajax.get('api/user/history_teacher_master_list', {params: params, func: {success: success}})
    },
    search() {
      this.listParam.keyword = this.keyword;
      this.listParam.date_begin = this.pickerDate.length > 0 ? this.pickerDate[0] : '';
      this.listParam.date_end = this.pickerDate.length > 0 ? this.pickerDate[1] : '';
      this.listParam.page_index = 1;
      this.getList();
    },
    reset() {
      this.keyword = '';
      this.pickerDate = [];
      this.listParam = {
        keyword: '',
        date_begin: '',
        date_end: '',
        page_index: 1,
        page_size: 10,
      }
      this.getList();
    },
    tableSelectionChange(val) {
      this.ids = [];
      if (val.length > 0) {
        val.forEach(item => {
          this.ids.push(item.id);
        })
      }
    },
    handleSizeChange(size) {
      this.listParam.page_size = size;
      this.getList();
    },
    handleCurrentChange(page) {
      this.listParam.page_index = page;
      this.getList();
    },
    toLink(link) {
      this.$router.push(link);
    },
    checkReject(obj) {/*查看拒绝理由 */
      this.rejectFlag = true;
      this.rejectTxt = obj.r_comment;
    },
    againPost(row) {//多级重新提交
      const params = {
        id: row.id
      }
      const success = (res => {
        this.getList()
        this.$message.success(res.msg)
      })
      const fail = (res => {
        this.$message.warning(res.msg)
      })

      this.$ajax.post('/api/user/history_teacher_master', params, {func: {success, fail}})
    },
    delAll() {
      if (this.ids.length <= 0) {
        this.$message.warning('请选择要删除的选项');
        return false;
      }

      this.delTergger();
    },
    del(id) {
      let params = {};
      if (id) {
        params.id = id;
      } else {
        params.id = this.ids;
      }
      const success = res => {
        this.$message.success(res.msg);
        this.ids = [];

        if (this.listData.length - this.rowLen === 0) {
          if (this.listParam.page_index > 1) {
            this.listParam.page_index--;
          } else {
            this.listParam.page_index = 1;
          }
        }

        this.getList();
      }
      this.$ajax.delete("api/user/history_teacher_master", {
        params: params,
        func: {success: success}
      });
    },
    delTergger(obj, type) {
      this.$confirm('确定要执行此操作吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (Object.is(type, 'one')) {
          this.rowLen = 1;
          this.del(obj.id);
        } else {
          this.rowLen = this.ids.length;
          this.del();
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    remove(id) {
      let params = {
        id: id,
      }
      const success = res => {
        this.$message.success(res.msg);

        if (this.listData.length - this.rowLen === 0) {
          if (this.listParam.page_index > 1) {
            this.listParam.page_index--;
          } else {
            this.listParam.page_index = 1;
          }
        }

        this.getList();
      }
      this.$ajax.put('api/user/history_teacher_master', params, {func: {success: success}})
    },
    removeTergger(obj) {
      this.$confirm('确定要执行此操作吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.rowLen = 1;
        this.remove(obj.id);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  },
}
</script>
